﻿using System;
using Microsoft.Phone.Controls;

namespace Amicus_Place_Finder.Views
{
    public partial class SettingPage : PhoneApplicationPage
    {
        public SettingPage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            try
            {
                Location.IsChecked = SettingUtils.Settings.IsLocationServiceEnabled;
                Facebook.IsChecked = SettingUtils.Settings.IsFacebookPlaceEnable;
                Google.IsChecked = SettingUtils.Settings.IsGooglePlaceEnable;
                Foursquare.IsChecked = SettingUtils.Settings.IsFoursquarePlaceEnable;
                Distance.Text = SettingUtils.Settings.MapSearchRadius.ToString();
            }
            catch { }
        }

        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);

            try
            {
                SettingUtils.Settings.IsLocationServiceEnabled = Location.IsChecked;
                SettingUtils.Settings.IsFacebookPlaceEnable = Facebook.IsChecked;
                SettingUtils.Settings.IsGooglePlaceEnable = Google.IsChecked;
                SettingUtils.Settings.IsFoursquarePlaceEnable = Foursquare.IsChecked;
                SettingUtils.Settings.MapSearchRadius = Convert.ToInt32(Distance.Text);
            }
            catch { }

            SettingUtils.SaveSettings();
        }

    }
}